/*
 * @Autor: dc
 * @Date: 2022-04-01 10:50:38
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-18 16:14:19
 * @Description: 施肥
 */
import React, { Component } from 'react';
import store from '../../../../redux/store'
import $ from 'jquery'
import './index.scss'

import { Toast } from 'antd-mobile'
import { actionBarConfig } from '../../../../redux/action/tree'

class index extends Component {
    fertilizerFun = () => {
        console.log('施肥')
        const { treeAnimation, addEnergy } = this.props
        const { operationArr } = store.getState()
        const { prepare, cooling } = operationArr.find(item => item.name === '施肥')
        if (prepare > 0) {
            Toast.show({
                content: '请耐心等待, 施肥充能中',
                maskClickable: false,
            })
            return;
        }
        $('.fertilizer').animate({
            "left": "30%",
            "bottom": "5%",
            "opacity": '1'
        }, 1500, function () {
            store.dispatch(actionBarConfig({
                name: '施肥',
                prepare: cooling,
            }, 1000))
            $('.fertilizer').addClass('scale');
            setTimeout(() => {
                $('.fertilizer').removeClass('scale');
                $('.fertilizer').animate({
                    "opacity": '0'
                }, 500)
                setTimeout(() => {
                    $('.fertilizer').css({ "bottom": "20%", 'left': 0 })
                    treeAnimation();
                    addEnergy();
                }, 1500)

            }, 2800)
        })
    }
    render() {
        return (
            <div className="fertilizer">
                <i className="fertilizer_img">
                    <img src={require('../../../../assets/operation/fertilizer.png')}
                        alt="" />
                    <img className="feiLiao"
                        src={require('../../../../assets/operation/niao.png')} alt="" />
                </i>
            </div>
        );
    }
}

export default index;